from django.db import models

from shops.models import ShopsModel


class UserModel(models.Model):
    """用户"""
    user_id = models.IntegerField(primary_key=True)
    user_name = models.CharField(max_length=64)
    password = models.CharField(max_length=32)
    mobile = models.CharField(max_length=32, blank=True, null=True)
    open_id = models.CharField(max_length=128, blank=True, null=True)
    wallet = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    email = models.CharField(max_length=32, blank=True, null=True)
    fullname = models.CharField(max_length=32, blank=True, null=True)
    gender = models.IntegerField(blank=True, null=True)
    status = models.IntegerField(blank=True, null=True)
    created_time = models.DateTimeField(blank=True, null=True)
    # lastvisit = models.DateTimeField(blank=True, null=True)


    class Meta:
        # managed = False
        db_table = 'users'


class UserAddressModel(models.Model):
    address_id = models.IntegerField(primary_key=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING)
    username = models.CharField(max_length=64)
    gender = models.IntegerField()
    mobile = models.CharField(max_length=32)
    address = models.CharField(max_length=256)
    longitude = models.CharField(max_length=32)
    latitude = models.CharField(max_length=32)
    tag = models.IntegerField(blank=True, null=True)
    is_default = models.IntegerField()
    status = models.IntegerField()
    created_time = models.DateTimeField()
    edit_time = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'user_address'


class Coupon(models.Model):
    coupon_id = models.IntegerField(primary_key=True)
    shop = models.ForeignKey(ShopsModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    type = models.IntegerField(blank=True, null=True)
    title = models.CharField(max_length=32, blank=True, null=True)
    target_money = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    discount_monry = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    end_time = models.DateTimeField(blank=True, null=True)
    add_time = models.DateTimeField(blank=True, null=True)
    number = models.IntegerField(blank=True, null=True)
    status = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'coupon'


class CouponAccept(models.Model):
    coupon_accept_id = models.IntegerField(primary_key=True)
    shop_id = models.IntegerField()
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING)
    mobile = models.CharField(max_length=32)
    coupon = models.ForeignKey(Coupon, on_delete=models.DO_NOTHING)
    add_time = models.DateTimeField()
    use_time = models.DateTimeField()
    status = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'coupon_accept'


class SearchRecord(models.Model):
    search_record_id = models.IntegerField(primary_key=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING)
    content = models.CharField(max_length=128)
    status = models.IntegerField()
    created_time = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'search_record'
